-
Notifications
You must be signed in to change notification settings - Fork 180
/
Copy pathusage.apt.vm
711 lines (543 loc) · 24 KB
/
usage.apt.vm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
~~ Licensed to the Apache Software Foundation (ASF) under one
~~ or more contributor license agreements. See the NOTICE file
~~ distributed with this work for additional information
~~ regarding copyright ownership. The ASF licenses this file
~~ to you under the Apache License, Version 2.0 (the
~~ "License"); you may not use this file except in compliance
~~ with the License. You may obtain a copy of the License at
~~
~~ http://www.apache.org/licenses/LICENSE-2.0
~~
~~ Unless required by applicable law or agreed to in writing,
~~ software distributed under the License is distributed on an
~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~~ KIND, either express or implied. See the License for the
~~ specific language governing permissions and limitations
~~ under the License.
------
Usage
------
Allan Ramirez
Brian Fox
------
2010-05-01
------
Usage
Brief examples of how to use the dependency goals:
%{toc|fromDepth=2}
* <<<dependency:copy>>>
This goal is meant to be bound to a lifecycle phase and configured in your
<<<pom.xml>>>. It will resolve the artifact from the repository and place a copy
in the specified location. Multiple artifacts can be defined in a single
execution. A default output directory is specified but can be overridden for
each ArtifactItem by setting the optional outputDirectory field. An
optional new name can be set to rename or the version stripped while copying.
The artifact version is optional. If not set, the plugin will attempt to resolve it from the
project dependencies and then the dependencyManagement section.
See the {{{#Overwrite_Rules}Overwrite Rules}} section for rules about how overwriting is handled.
[]
Configure the plugin something like this if you intend to bind it to execute along with your build:
+---+
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>${project.version}</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>[ groupId ]</groupId>
<artifactId>[ artifactId ]</artifactId>
<version>[ version ]</version>
<type>[ packaging ]</type>
<classifier> [classifier - optional] </classifier>
<overWrite>[ true or false ]</overWrite>
<outputDirectory>[ output directory ]</outputDirectory>
<destFileName>[ filename ]</destFileName>
</artifactItem>
</artifactItems>
<!-- other configurations here -->
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>
+---+
If you intend to configure this goal for execution on the command line using:
---
mvn dependency:copy
---
you must not put the configuration inside the <executions> tag. Your configuration should look like this:
+---+
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>${project.version}</version>
<configuration>
<artifactItems>
<artifactItem>
<groupId>[ groupId ]</groupId>
<artifactId>[ artifactId ]</artifactId>
<version>[ version ]</version>
<type>[ packaging ]</type>
<classifier> [classifier - optional] </classifier>
<overWrite>[ true or false ]</overWrite>
<outputDirectory>[ output directory ]</outputDirectory>
<destFileName>[ filename ]</destFileName>
</artifactItem>
</artifactItems>
<!-- other configurations here -->
</configuration>
</plugin>
</plugins>
</build>
[...]
</project>
+---+
<Notes:>
* By default, artifacts are copied into <outputDirectory> using the
Maven artifact file name convention (that is, <artifactId-version-classifier.type>).
Use the following rules to override the default convention:
* Use <artifactItem.destFileName> to override the default file name.
* Use <stripVersion> to remove <version> from default file name.
This field is ignored when <artifactId.destFileName> is set.
* Use <artifactItem.outputDirectory> to override the plugin's <outputDirectory> configuration
per <artifactItem>.
[]
[]
* <<<dependency:copy-dependencies>>>
This goal can be bound to a lifecycle phase and configured in your <<<pom.xml>>>.
It will resolve the dependencies (including transitive dependencies) from
the repository and place a copy in the specified location.
The artifacts can be placed in subfolders based on type. For example:
\outputDirectory
\outputDirectory\jars
\outputDirectory\wars
The artifacts can be placed in a subfolder per artifact. For example:
\outputDirectory\junit-junit-3.8.1\
This feature also works with the subfolders per type. For example:
\outputDirectory\jars\junit-junit-3.8.1\
Artifacts can also be resolved by specifying the classifier and optionally
type. Type is only used with the classifier and defaults to java-sources.
When the classifier is set, the list of dependencies is used as the base to
resolve artifacts with the classifier and type. For example:
<<<mvn dependency:copy-dependencies -Dclassifier=sources>>> will try to find
the sources for all dependencies and copy them.
Also included is the ability to include or exclude by type (war, jar, etc.), scope (runtime, test, etc.), classifier (jdk14, sources, etc.), groupId, artifactId, or a combination of them.
<<Note:>> You may mix includes and excludes of the same category (e.g. scope). Includes are processed before excludes.
See the {{{#Overwrite_Rules}Overwrite Rules}} section for rules about how overwriting is handled.
The goal can also be launched from the command line like:
<<<mvn dependency:copy-dependencies [optional params]>>>
+---+
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>${project.version}</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<!-- configure the plugin here -->
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>
+---+
* <<<dependency:unpack>>>
This goal is meant to be bound to a lifecycle and configured in your pom.xml.
It will resolve the artifact from the repository and place a copy in the
specified location. Multiple artifacts can be defined in a single execution.
A default outputDirectory is specified but can be overridden for each
ArtifactItem by setting the optional outputDirectory field.
A single artifact can be unpacked multiple times if different include/exclude parameters
are defined for each artifactItem
See the {{{#Overwrite_Rules}Overwrite Rules}} section for rules about how overwriting is handled.
The artifact version is optional. If not set, the plugin will attempt to resolve it from the
project dependencies and then the dependencyManagement section.
Configure the plugin something like this if you intend to bind it to execute along with your build:
+---+
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>${project.version}</version>
<executions>
<execution>
<id>unpack</id>
<phase>package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<!-- configure the plugin here -->
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>
+---+
If you intend to configure this goal for execution on the command line using:
---
mvn dependency:unpack
---
you must not put the configuration inside the <executions> tag. Your configuration should look like this:
+---+
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>${project.version}</version>
<configuration>
<artifactItems>
<artifactItem>
<groupId>[ groupId ]</groupId>
<artifactId>[ artifactId ]</artifactId>
<version>[ version ]</version>
<type>[ packaging ]</type>
<classifier> [classifier - optional] </classifier>
<overWrite>[ true or false ]</overWrite>
<outputDirectory>[ output directory ]</outputDirectory>
<includes>[ comma separated list of file filters ]</includes>
<excludes>[ comma separated list of file filters ]</excludes>
</artifactItem>
</artifactItems>
<!-- other configurations here -->
</configuration>
</plugin>
</plugins>
</build>
[...]
</project>
+---+
* <<<dependency:unpack-dependencies>>>
This goal can be bound to a lifecycle and configured in your pom.xml.
It will resolve the dependencies (including transitive dependencies) from
the repository and unpack them to the specified location.
Unpack-dependencies includes transitive dependencies by default. To include
only direct dependencies, set the excludeTransitive parameter to true.
Dependencies can be included or excluded by a list of types. See
{{{./unpack-dependencies-mojo.html}unpack-dependencies}} for details.
The artifacts can be unpacked in subfolders based on type. For example:
\outputDirectory
\outputDirectory\jars
\outputDirectory\wars
The artifacts can be placed in a subfolder per artifact. For example:
\outputDirectory\junit-junit-3.8.1\
This feature also works with the subfolders per type. For example:
\outputDirectory\jars\junit-junit-3.8.1\
Artifacts can also be resolved by specifying the classifier and optionally
type. Type is only used with the classifier and defaults to java-sources.
When the classifier is set, the list of dependencies is used as the base to
resolve artifacts with the classifier and type. For example:
<<<mvn dependency:unpack-dependencies -Dclassifier=sources>>> will try to find
the sources for all dependencies and unpack them.
Filters can be applied to include or exclude files or filesets as necessary
Also included is the ability to include or exclude by type (war, jar, etc.), scope (runtime, test, etc.), classifier (jdk14, sources, etc.), groupId, artifactId, or a combination of them.
<<Note:>> You can mix includes and excludes of the same category (e.g. scope). Includes are processed before excludes.
See the {{{#Overwrite_Rules}Overwrite Rules}} section for rules about how overwriting is handled.
The goal can also be launched from the command line like:
<<<mvn dependency:unpack-dependencies [optional params]>>>
+---+
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>${project.version}</version>
<executions>
<execution>
<id>unpack-dependencies</id>
<phase>package</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<!-- configure the plugin here -->
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>
+---+
** Overwrite Rules
Artifacts are copied or unpacked using the following rules:
* If the artifact doesn't exist in the destination, then copy/unpack it.
Otherwise:
* For copy/unpack goal only: if <<<artifactItem / overWrite>>> or <<<overWrite>>> is true, then it will force an overwrite.
* Releases check the <<<overWriteReleases>>> value (default = false). If true, then it will force an overwrite.
* Snapshots check the <<<overWriteSnapshots>>> value (default = false). If true, then it will force an overwrite.
* If none of the above is set to true, then it defaults to the <<<overWriteIfNewer>>> value (default = true). This value, if true, causes
the plugin to only copy if the source is newer than the destination (or it doesn't exist in the destination). (for unpack, this checks the existence of the marker file, created in the <<<markersDirectory>>> path.
To avoid unexpected behavior after <<<mvn clean>>>, this path should normally be contained within the <<</target>>> hierarchy.)
Examples:
* Using the default settings (<<<overWriteReleases>>> = false, <<<overWriteSnapshots>>> = false, <<<overWriteIfNewer>>> = true), then a release or snapshot artifact will
only over write the destination if the source is newer than the destination (or marker file if unpacking).
* If <<<overWriteReleases>>> = true, then a release artifact (e.g. <<<foo-1.0.jar>>>) will always overwrite.
* If <<<overWriteSnapshots>>> = true, then a snapshot artifact (e.g. <<<foo-1.0-SNAPSHOT.jar>>>) will always overwrite.
* If all of the values are false, then a copy/unpack will only occur if it doesn't exist in the destination (or <<<markersDirectory>>> if unpacking).
* <<<dependency:resolve>>>
Resolve is intended to be used from the command line like:
<<<mvn dependency:resolve -Dsilent=true>>>
This goal resolves all test and compile scoped
dependencies and then displays the resolved versions. This
ensures all dependencies are downloaded to the local repository. This is
useful when troubleshooting or during intermittent remote repository
failures when repeatedly building multiproject modules is undesirable and
the build is failing on dependency resolution. It can also be used to quickly
determine how versions are being resolved.
Artifacts can also be resolved by specifying the classifier and optionally
type. Type is only used with the classifier and defaults to java-sources.
When the classifier is set, the list of dependencies is used as the base to
resolve artifacts with the classifier and type. For example:
<<<mvn dependency:resolve -Dclassifier=test-jar>>> will try to find the
test-jar for all dependencies resolve them to the local repository.
* <<<dependency:resolve-sources>>>
Resolve-sources is intended to be used from the command line like:
<<<mvn dependency:resolve-sources -Dsilent=true>>>
This is the same as the resolve goal except it includes the source
attachments if they exist. This is useful when you want to download source
attachments to your local repository.
You can also define the <<<markersDirectory>>> either in the pom or settings
to be a common location for all projects. This allows the system to resolve sources faster for dependencies that don't
have the sources published. The plugin will store a marker file to describe if the sources were resolved or not. By placing
them in a common location, multiple attempts to resolve non-existent sources will be avoided.
* <<<dependency:resolve-plugins>>>
Resolve-plugins is intended to be used from the command line like:
<<<mvn dependency:resolve-plugins -Dsilent=true -DexcludeTransitive=true>>>
This is the same as the resolve goal except it resolves plugins and
optionally their dependencies.
* <<<dependency:go-offline>>>
This goal is exactly the same as calling
<<<mvn dependency:resolve dependency:resolve-plugins>>>.
* <<<dependency:purge-local-repository>>>
This goal is meant to delete all of the dependencies for the current project
(or projects, in the case of a multimodule build) from the local repository.
Purges can be run with a variety of limiting parameters, including artifact
exclusions, limiting to direct dependencies only, and different levels of
depth for deletion. By default, deleted artifacts can be re-resolved
afterwards; you can disable this by specifying <<<-DreResolve=false>>>.
In its simplest form, the goal can be called like this:
---
mvn dependency:purge-local-repository
---
To add the restriction that the <<<org.apache.maven:maven-plugin-api>>>
artifact not be deleted, we can modify the command to this:
---
mvn dependency:purge-local-repository -Dexclude=org.apache.maven:maven-plugin-api
---
<<Note:>> The <<<exclude>>> parameter is a comma-delimited list of
groupId:artifactId pairs. It has a corresponding List-based parameter -
<<<excludes>>> - for convenient use inside the POM.
Another handy aspect of this goal is the ability to wipe out artifacts at
varying depths. These depths are:
* <<file>> - Delete just the artifact's file.
* <<version>> - Delete the version directory containing this artifact. Amounts to
<<<file.getParentFile()>>>.
* <<artifactId>> - Delete the artifactId directory containing this artifact.
Amounts to <<<file.getParentFile().getParentFile()>>>.
* <<groupId>> - Delete the groupId directory structure containing this artifact.
At a minimum, this amounts to <<<file.getParentFile().getParentFile().getParentFile()>>>.
However, if the groupId contains multiple parts, the goal will prune all groupId-part
directories that contain only the files associated with this artifact. Again, note that
the exception to this pruning algorithm is the lowest groupId part, which will always
be pruned.
[]
To prune dependency artifacts back to their associated artifactId directories
(in order to verify proper artifact resolution, for example), simply use this
command:
---
mvn dependency:purge-local-repository -DresolutionFuzziness=artifactId
---
Finally, it's possible to bind this goal to the build lifecycle. One reason for this
might be to clean out all dependencies when the build is initialized, to verify
correct resolution.
* <<<dependency:analyze>>>
This goal performs byte code analysis to determine missing or unused dependencies. This goal is meant to be launched from the command line. It will fork the build and execute test-compile so there are class files to analyze.
If you want to bind analyze in your pom, use the <<<dependency:analyze-only>>> instead.
This goal can be executed from the command line:
---
mvn dependency:analyze
---
Sample output:
+---+
[INFO] [dependency:analyze]
[WARNING] Used undeclared dependencies found:
[WARNING] classworlds:classworlds:jar:1.1-alpha-2:compile
[WARNING] org.apache.maven.shared:maven-invoker:jar:2.0.7-SNAPSHOT:test
+---+
* <<<dependency:analyze-dep-mgt>>>
This goal looks at the dependencies after final resolution and looks for mismatches in your dependencyManagement section.
This goal is useful for detecting projects that override the dependencyManagement directly. Set ignoreDirect to false to detect these otherwise normal conditions.
This goal can be executed from the command line:
---
mvn dependency:analyze-dep-mgt
---
Sample output:
+---+
[INFO] Found Resolved Dependency / DependencyManagement mismatches:
[INFO] Dependency: commons-lang:commons-lang:jar
[INFO] DepMgt : 1.0
[INFO] Resolved: 2.3
[INFO] Dependency: commons-digester:commons-digester:jar
[INFO] DepMgt : 1.6
[INFO] Resolved: 1.7
[INFO] Dependency: javax.servlet:servlet-api:jar
[INFO] DepMgt : 2.3
[INFO] Resolved: 2.4
[WARNING] Potential problems found in Dependency Management
+---+
* <<<dependency:analyze-report>>>
This goal is used to include a report of the dependencies in the output of the <<<maven-site-plugin>>>.
+-------+
<reporting>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>${project.version}</version>
<reportSets>
<reportSet>
<reports>
<report>analyze-report</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
+-------+
* <<<dependency:tree>>>
This goal is used to view the dependency hierarchy of the project currently being built.
It will output the resolved tree of dependencies that the Maven build process actually uses.
This goal can be executed from the command line:
---
mvn dependency:tree
---
Optionally, the <<<output>>> parameter can be specified to divert the output to a file:
---
mvn dependency:tree -DoutputFile=/path/to/file
---
Also, the <<<outputType>>> parameter can be used to generate different formats of output. The
following formats are currently supported:
* text
* {{{https://en.wikipedia.org/wiki/DOT_language}dot}}
* {{{https://en.wikipedia.org/wiki/GraphML}graphml}}
* {{{https://en.wikipedia.org/wiki/Trivial_Graph_Format}tgf}}
[]
---
mvn dependency:tree -DoutputFile=/path/to/file.graphml -DoutputType=graphml
---
* <<<dependency:build-classpath>>>
This goal will output a classpath string of dependencies from the local repository to a file or log and optionally attach and deploy the file. For instance, the file would contain a classpath string like this:
---
/home/foo/.m2/repository/org/java/utils/util/util-1.0.jar:/home/foo/.m2/ ....
---
The resulting file could then be used like this:
---
java -cp `cat resultFile` MyClass
---
In its simplest form, to output the classpath to the log, the goal can be called like this:
---
mvn dependency:build-classpath
---
or to write the classpath to cp.txt:
---
mvn dependency:build-classpath -Dmdep.outputFile=cp.txt
---
The goal can also be bound to a lifecycle phase with the following configuration:
+---+
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>${project.version}</version>
<executions>
<execution>
<id>build-classpath</id>
<phase>generate-sources</phase>
<goals>
<goal>build-classpath</goal>
</goals>
<configuration>
<!-- configure the plugin here -->
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>
+---+
* <<<dependency:list-repositories>>>
This goal lists all the repositories that this build depends upon. It shows repositories defined in your settings,
poms, and declared in transitive dependency poms.
* <<<dependency:get>>>
This goal resolves an artifact and (optionally) its dependencies from remote repositories using its Maven coordinates.
The Maven Central repository are always consider during resolving.
---
mvn dependency:get -DgroupId=org.apache.maven -DartifactId=maven-core -Dversion=2.2.1 -Dpackaging=jar -Dclassifier=sources
mvn dependency:get -DgroupId=org.apache.maven -DartifactId=maven-core -Dversion=2.2.1 -Dpackaging=jar -Dclassifier=sources -DremoteRepositories=https://myrepo.com/maven2
---
* <<<dependency:analyze-exclusions>>>
This goal checks exclusions on dependencies and checks if the artifact actually brings in the given dependency.
For instance, given dependency a:b:1.0 transitively includes x:y:1.0 which you do not want for some reason and exclude it.
Later a:b:2.0 has removed the unwanted dependency and you upgrade. This goal will inform you that the exclusion is no
longer required.
---
mvn dependency:analyze-exclusions
---
Sample output:
+---+
[WARNING] The following dependencies defines unnecessary excludes
[WARNING] org.apache.maven:maven-artifact:
[WARNING] - javax.annotation:javax.annotation-api
[WARNING] - javax.activation:javax.activation-api
+---+